mui.init({});


mui.plusReady(function(){
	loadDatas();
	
});

function loadDatas(){
	var self = plus.webview.currentWebview();
	var formId = self.formId;
	var sessionId =	plus.storage.getItem(KeyCfg.JSESSIONID);
	var url = UrlConfig.trade_record;
	//var formData = $("#myform").serialize();
	var formData = {transferLoanId:formId,sessionId:sessionId};
	MuiEventMgr.ajax(url,{pars:formData,
	  	sfn : function(data){
	  		callback(data);
	  	},ffn : function(err){
	  		mui.alert("获取数据失败：["+err+"]");
	  	}
	 });
}

function callback(data){	
	var accountinfoList = data.accountinfoList;
	if(typeof(accountinfoList) == 'undefined'){
		$(".tradeRecord-header").css("display","none");
		$(".tradeRecord-info").css("display","none");
		$(".tradeRecord-table").css("display","none");
		$("#noRecord").css("display","");
		$(".mui-table-view").css("display","");
		//mui.alert("                         暂无记录!");
		return;
	}
	var htmlArr = [];
	for(var i=0,count=accountinfoList.length; i<count; i++){
		var accountinfo = accountinfoList[i];
		var html = getHtml(accountinfo);
		htmlArr[i] = html;
	}
	var htmlCodes = htmlArr.join("  ");
	$("#tradeRecord-info").html(htmlCodes);

}

function getHtml(accountinfo){
	var time =accountinfo.time;
	var type = accountinfo.type;
	var num=accountinfo.num;
	var expenditureMoney =accountinfo.expenditureMoney; //支出
	var outclassStr = '';
	var inclassStr = '';
	if(expenditureMoney=='0.00'||expenditureMoney=='0'){
		outclassStr = "style='display:none;'";
	}
	var incomeMoney =accountinfo.incomeMoney;//收入
	if(incomeMoney=='0.00'||incomeMoney=='0'){
		inclassStr = "style='display:none;'";
	}
	var money =accountinfo.money; //余额
	var use = accountinfo.use;//说明

var htmls = [
		'<table class="tradeRecord-table" border="0">',
				'<tbody>',
					'<tr>',
						'<td class="time" >'+time+'</td>',
						'<td class="use" >'+type+'</td>',
						'<td class="money" ><div class="lcy_expenditure" id="lcy_expenditure" '+outclassStr+'>-'+expenditureMoney+'</div> <div class="lcy_income" id="lcy_income" '+inclassStr+'>+'+incomeMoney+'</div></td>',
						'<td class="balance">￥'+money+'</td>',
					'</tr>',
				'</tbody>',
			'</table>'
			];
	return htmls.join(" ");
}